/*
 * @Author: SeonHu
 * @Date: 2025-09-16 14:44:19
 * @LastEditors: SeonHu
 * @LastEditTime: 2025-09-23 15:28:25
 * @FilePath: \bg-vben\src\api\report\admin\print\index.ts
 * @Description:
 * Copyright © 2020-2025 SANQING Corporation, All rights reserved.
 */
import type { OrganizationNodeSimple } from '@/api/identity/admin/organization/model';
import type { UserNode } from '@/api/identity/admin/user/model';

import type {
  OrganizationSetPrintTemplateDto,
  PrintInputDto,
  PrintLogOutputDto,
  PrintOrganizationDto,
  PrintOutputDto,
  PrintTemplateFileInputDto,
  PrintTemplateInputDto,
  PrintTemplateInputDtoSimple,
  PrintTemplateNode,
  PrintTemplateOrganizationDto,
  PrintTemplateOrganizationOutputDtoSimple,
  PrintTemplateOutputDto,
  PrintTemplateSetOrganizationDto,
  PrintTemplateSetUserDto,
  PrintTemplateUserDto,
  PrintTemplateUserOutputDtoSimple,
  PrintUserDto,
  UserSetPrintTemplateDto,
} from './model';

import type { ErrorMessageMode, PageData } from '#/request';

import { PrintReportTypeEnum } from '@/enums/report/printReportTypeEnum';
import { request } from '@/utils/request/axios';

import { PageRequest } from '#/request';

/** 报表打印模块URL枚举 */
enum Api {
  /** 获取打印报告文件 */
  GetReportFile = '/api/report/admin/print/getReportFile',
  /** 获取数据源连接集合 */
  GetDsConnections = '/api/report/admin/print/getDsConnections',
  /** 获取数据源配置XML */
  GetDsConfigXml = '/api/report/admin/print/getDsConfigXml',
  /** 获取数据源配置XSD */
  GetDsConfigXsd = '/api/report/admin/print/getDsConfigXsd',
  /** 读取打印 */
  ReadPrints = '/api/report/admin/print/readPrints',
  /** 创建打印 */
  CreatePrints = '/api/report/admin/print/createPrints',
  /** 更新打印 */
  UpdatePrints = '/api/report/admin/print/updatePrints',
  /** 删除打印 */
  DeletePrints = '/api/report/admin/print/deletePrints',
  /** 读取模板 */
  ReadTemplates = '/api/report/admin/print/readTemplates',
  /** 创建模板 */
  CreateTemplates = '/api/report/admin/print/createTemplates',
  /** 更新模板 */
  UpdateTemplates = '/api/report/admin/print/updateTemplates',
  /** 更新模板信息 */
  UpdateTemplateInfos = '/api/report/admin/print/updateTemplateInfos',
  /** 更新模板文件 */
  UpdateTemplateFiles = '/api/report/admin/print/updateTemplateFiles',
  /** 删除模板 */
  DeleteTemplates = '/api/report/admin/print/deleteTemplates',
  /** 获取模板文件 */
  GetTemplateFile = '/api/report/admin/print/getTemplateFile',
  /** 读取打印[用户]树数据 */
  ReadPrintUserNodes = '/api/report/admin/print/readPrintUserNodes',
  /** 读取用户[打印]树数据 */
  ReadUserPrintNodes = '/api/report/admin/print/readUserPrintNodes',
  /** 设置用户的打印 */
  SetUserPrints = '/api/report/admin/print/setUserPrints',
  /** 设置打印的用户 */
  SetPrintUsers = '/api/report/admin/print/setPrintUsers',
  /** 读取打印用户 */
  ReadPrintUsers = '/api/report/admin/print/readPrintUsers',
  /** 创建打印用户 */
  CreatePrintUsers = '/api/report/admin/print/createPrintUsers',
  /** 取消打印用户默认设置 */
  CancelDefaultPrintUsers = '/api/report/admin/print/cancelDefaultPrintUsers',
  /** 设置打印用户默认设置 */
  SetDefaultPrintUsers = '/api/report/admin/print/setDefaultPrintUsers',
  /** 删除打印用户 */
  DeletePrintUsers = '/api/report/admin/print/deletePrintUsers',
  /** 清除打印用户 */
  ClearPrintUsers = '/api/report/admin/print/clearPrintUsers',
  /** 根据模板清除打印用户 */
  ClearPrintUsersByTemplate = '/api/report/admin/print/clearPrintUsersByTemplate',
  /** 根据打印清除打印用户 */
  ClearPrintUsersByPrint = '/api/report/admin/print/clearPrintUsersByPrint',
  /** 读取打印[组织]树数据 */
  ReadPrintOrganizationNodes = '/api/report/admin/print/readPrintOrganizationNodes',
  /** 读取组织[打印]树数据 */
  ReadOrganizationPrintNodes = '/api/report/admin/print/readOrganizationPrintNodes',
  /** 设置组织的打印 */
  SetOrganizationPrints = '/api/report/admin/print/setOrganizationPrints',
  /** 设置打印的组织 */
  SetPrintOrganizations = '/api/report/admin/print/setPrintOrganizations',
  /** 读取打印组织 */
  ReadPrintOrganizations = '/api/report/admin/print/readPrintOrganizations',
  /** 创建打印组织 */
  CreatePrintOrganizations = '/api/report/admin/print/createPrintOrganizations',
  /** 删除打印组织 */
  DeletePrintOrganizations = '/api/report/admin/print/deletePrintOrganizations',
  /** 清除打印组织 */
  ClearPrintOrganizations = '/api/report/admin/print/clearPrintOrganizations',
  /** 根据模板清除打印组织 */
  ClearPrintOrganizationsByTemplate = '/api/report/admin/print/clearPrintOrganizationsByTemplate',
  /** 根据打印清除打印组织 */
  ClearPrintOrganizationsByPrint = '/api/report/admin/print/clearPrintOrganizationsByPrint',
  /** 读取打印日志 */
  ReadPrintLogs = '/api/report/admin/print/readPrintLogs',
}

// #region 获取打印报告文件
/**
 * 获取打印报告文件
 * @param printReportType 打印报告类型
 * @param mode 错误消息模型
 */
export function getReportFile(printReportType: PrintReportTypeEnum, mode: ErrorMessageMode = 'message') {
  return request.get<any>(
    {
      url: Api.GetReportFile,
      params: { printReportType },
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 获取数据源连接集合
/**
 * 获取数据源连接集合
 * @param printReportType 打印报告类型
 * @param mode 错误消息模型
 */
export function getDsConnections(printReportType: PrintReportTypeEnum, mode: ErrorMessageMode = 'message') {
  return request.get(
    {
      url: Api.GetDsConnections,
      params: { printReportType },
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 获取数据源配置XML
/**
 * 获取数据源配置XML
 * @param mode 错误消息模型
 */
export function getDsConfigXml(mode: ErrorMessageMode = 'message') {
  return request.get<any>(
    {
      url: Api.GetDsConfigXml,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 获取数据源配置XSD
/**
 * 获取数据源配置XSD
 * @param mode 错误消息模型
 */
export function getDsConfigXsd(mode: ErrorMessageMode = 'message') {
  return request.get(
    {
      url: Api.GetDsConfigXsd,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion

// #region 读取打印
/**
 * 读取打印
 * @param params 分页请求
 * @param mode 错误消息模型
 */
export function readPrints(params: PageRequest, mode: ErrorMessageMode = 'message') {
  // console.log('readPrints', { request });
  return request.post<PageData<PrintOutputDto>>(
    {
      url: Api.ReadPrints,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 创建打印
/**
 * 创建打印
 * @param dtos 输入DTO
 * @param mode 错误消息模型
 */
export function createPrints(dtos: PrintInputDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.CreatePrints,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 更新打印
/**
 * 更新打印
 * @param dtos 输入DTO
 * @param mode 错误消息模型
 */
export function updatePrints(dtos: PrintInputDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.UpdatePrints,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 删除打印
/**
 * 删除打印
 * @param printIds 打印编号
 * @param mode 错误消息模型
 */
export function deletePrints(printIds: (bigint | string)[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.DeletePrints,
      params: printIds,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion

// #region 读取模板
/**
 * 读取模板
 * @param params 分页请求
 * @param mode 错误消息模型
 */
export function readTemplates(params: PageRequest, mode: ErrorMessageMode = 'message') {
  return request.post<PageData<PrintTemplateOutputDto>>(
    {
      url: Api.ReadTemplates,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 创建模板
/**
 * 创建模板
 * @param dtos 输入DTO
 * @param mode 错误消息模型
 */
export function createTemplates(dtos: PrintTemplateInputDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.CreateTemplates,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 更新模板
/**
 * 更新模板
 * @param dtos 输入DTO
 * @param mode 错误消息模型
 */
export function updateTemplates(dtos: PrintTemplateInputDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.UpdateTemplates,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 更新模板信息
/**
 * 更新模板信息
 * @param dtos 输入DTO
 * @param mode 错误消息模型
 */
export function updateTemplateInfos(dtos: PrintTemplateInputDtoSimple[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.UpdateTemplateInfos,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 更新模板文件
/**
 * 更新模板文件
 * @param dtos 输入DTO
 * @param mode 错误消息模型
 */
export function updateTemplateFiles(dtos: PrintTemplateFileInputDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.UpdateTemplateFiles,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 删除模板
/**
 * 删除模板
 * @param templateIds 模板编号
 * @param mode 错误消息模型
 */
export function deleteTemplates(templateIds: (bigint | string)[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.DeleteTemplates,
      params: templateIds,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 获取模板文件
/**
 * 获取模板文件
 * @param templateId 模板编号
 * @param mode 错误消息模型
 */
export function getTemplateFile(templateId: bigint | string, mode: ErrorMessageMode = 'message') {
  return request.get(
    {
      url: Api.GetTemplateFile,
      params: { templateId },
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion

// #region 读取打印[用户]树数据
/**
 * 读取打印[用户]树数据
 * @param templateId 模板编号
 * @param mode 错误消息模型
 */
export function readPrintUserNodes(templateId: bigint | string, mode: ErrorMessageMode = 'message') {
  return request.get<UserNode[]>(
    {
      url: Api.ReadPrintUserNodes,
      params: { templateId },
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 读取用户[打印]树数据
/**
 * 读取用户[打印]树数据
 * @param userId 用户编号
 * @param mode 错误消息模型
 */
export function readUserPrintNodes(userId: bigint | string, mode: ErrorMessageMode = 'message') {
  return request.get<PrintTemplateNode[]>(
    {
      url: Api.ReadUserPrintNodes,
      params: { userId },
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 设置用户的打印
/**
 * 设置用户的打印
 * @param dtos 用户打印模板
 * @param mode 错误消息模型
 */
export function setUserPrints(dtos: UserSetPrintTemplateDto, mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.SetUserPrints,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 设置打印的用户
/**
 * 设置打印的用户
 * @param dtos 打印模板用户
 * @param mode 错误消息模型
 */
export function setPrintUsers(dtos: PrintTemplateSetUserDto, mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.SetPrintUsers,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 读取打印用户
/**
 * 读取打印用户
 * @param params 分页请求
 * @param mode 错误消息模型
 */
export function readPrintUsers(params: PageRequest, mode: ErrorMessageMode = 'message') {
  return request.post<PageData<PrintTemplateUserOutputDtoSimple>>(
    {
      url: Api.ReadPrintUsers,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 创建打印用户
/**
 * 创建打印用户
 * @param dtos 输入DTO
 * @param mode 错误消息模型
 */
export function createPrintUsers(dtos: PrintTemplateUserDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.CreatePrintUsers,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 取消打印用户默认设置
/**
 * 取消打印用户默认设置
 * @param dtos 输入DTO
 * @param mode 错误消息模型
 */
export function cancelDefaultPrintUsers(dtos: PrintUserDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.CancelDefaultPrintUsers,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 设置打印用户默认设置
/**
 * 设置打印用户默认设置
 * @param dtos 输入DTO
 * @param mode 错误消息模型
 */
export function setDefaultPrintUsers(dtos: PrintTemplateUserDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.SetDefaultPrintUsers,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 删除打印用户
/**
 * 删除打印用户
 * @param dtos 输入DTO
 * @param mode 错误消息模型
 */
export function deletePrintUsers(dtos: PrintTemplateUserDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.DeletePrintUsers,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 清除打印用户
/**
 * 清除打印用户
 * @param dtos 输入DTO
 * @param mode 错误消息模型
 */
export function clearPrintUsers(dtos: PrintUserDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.ClearPrintUsers,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 根据模板清除打印用户
/**
 * 根据模板清除打印用户
 * @param templateIds 模板编号
 * @param mode 错误消息模型
 */
export function clearPrintUsersByTemplate(templateIds: (bigint | string)[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.ClearPrintUsersByTemplate,
      params: templateIds,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 根据打印清除打印用户
/**
 * 根据打印清除打印用户
 * @param printIds 打印编号
 * @param mode 错误消息模型
 */
export function clearPrintUsersByPrint(printIds: (bigint | string)[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.ClearPrintUsersByPrint,
      params: printIds,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion

// #region 读取打印[组织]树数据
/**
 * 读取打印[组织]树数据
 * @param templateId 模板编号
 * @param mode 错误消息模型
 */
export function readPrintOrganizationNodes(templateId: bigint | string, mode: ErrorMessageMode = 'message') {
  return request.get<OrganizationNodeSimple[]>(
    {
      url: Api.ReadPrintOrganizationNodes,
      params: { templateId },
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 读取组织[打印]树数据
/**
 * 读取组织[打印]树数据
 * @param organizationId 组织机构编号
 * @param mode 错误消息模型
 */
export function readOrganizationPrintNodes(organizationId: bigint | string, mode: ErrorMessageMode = 'message') {
  return request.get<PrintTemplateNode[]>(
    {
      url: Api.ReadOrganizationPrintNodes,
      params: { organizationId },
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 设置组织的打印
/**
 * 设置组织的打印
 * @param dtos 组织机构打印模板
 * @param mode 错误消息模型
 */
export function setOrganizationPrints(dtos: OrganizationSetPrintTemplateDto, mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.SetOrganizationPrints,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 设置打印的组织
/**
 * 设置打印的组织
 * @param dtos 打印模板组织机构
 * @param mode 错误消息模型
 */
export function setPrintOrganizations(dtos: PrintTemplateSetOrganizationDto, mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.SetPrintOrganizations,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 读取打印组织
/**
 * 读取打印组织
 * @param params 分页请求
 * @param mode 错误消息模型
 */
export function readPrintOrganizations(params: PageRequest, mode: ErrorMessageMode = 'message') {
  return request.post<PageData<PrintTemplateOrganizationOutputDtoSimple>>(
    {
      url: Api.ReadPrintOrganizations,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 创建打印组织
/**
 * 创建打印组织
 * @param dtos 输入DTO
 * @param mode 错误消息模型
 */
export function createPrintOrganizations(dtos: PrintTemplateOrganizationDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.CreatePrintOrganizations,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 删除打印组织
/**
 * 删除打印组织
 * @param dtos 输入DTO
 * @param mode 错误消息模型
 */
export function deletePrintOrganizations(dtos: PrintTemplateOrganizationDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.DeletePrintOrganizations,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 清除打印组织
/**
 * 清除打印组织
 * @param dtos 输入DTO
 * @param mode 错误消息模型
 */
export function clearPrintOrganizations(dtos: PrintOrganizationDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.ClearPrintOrganizations,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 根据模板清除打印组织
/**
 * 根据模板清除打印组织
 * @param templateIds 模板编号
 * @param mode 错误消息模型
 */
export function clearPrintOrganizationsByTemplate(
  templateIds: (bigint | string)[],
  mode: ErrorMessageMode = 'message',
) {
  return request.post(
    {
      url: Api.ClearPrintOrganizationsByTemplate,
      params: templateIds,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 根据打印清除打印组织
/**
 * 根据打印清除打印组织
 * @param printIds 打印编号
 * @param mode 错误消息模型
 */
export function clearPrintOrganizationsByPrint(printIds: (bigint | string)[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.ClearPrintOrganizationsByPrint,
      params: printIds,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion

// #region 读取打印日志
/**
 * 读取打印日志
 * @param params 分页请求
 * @param mode 错误消息模型
 */
export function readPrintLogs(params: PageRequest, mode: ErrorMessageMode = 'message') {
  return request.post<PageData<PrintLogOutputDto>>(
    {
      url: Api.ReadPrintLogs,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
